//
//  TngHttpClient.m
//  PropertyManager
//
//  Created by TNG on 2018/9/26.
//  Copyright © 2018年 Tng. All rights reserved.
//

#import "TngHttpClient.h"

@implementation TngHttpClient

+(TngHttpClient *)shareClient
{
    [[Reachability reachabilityForInternetConnection] startNotifier];
    static TngHttpClient * http = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        http = [[TngHttpClient alloc] initWithBaseURL:[NSURL URLWithString:BASE_URL]];
    });
    //        https://blog.csdn.net/czh880410/article/details/52057501
    return http;
}

-(instancetype) initWithBaseURL:(NSURL *)url
{
    self = [super initWithBaseURL:url];
    if (self)
    {
        self.responseSerializer = [AFHTTPResponseSerializer serializer];
        self.requestSerializer.timeoutInterval = 15;
        [self.requestSerializer setValue:@"*/*" forHTTPHeaderField:@"Accept"];
        [self.requestSerializer setValue:SFMToken forHTTPHeaderField:@"X-AUTH-TOKEN"];
        self.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/html", nil];
    }
    return self;
}

@end
